package com.android.djlmapp.activity.kaika.web;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.djlmapp.R;
import com.android.djlmapp.activity.home.web.base.BaseWebActivity;
import com.android.djlmapp.activity.order.OrderListActivity;
import com.android.djlmapp.http.ComPareUtils;
import com.android.djlmapp.http.GlobalUrls;
import com.android.djlmapp.token.GetUrlStr;
import com.android.djlmapp.view.WebView4Scroll;
import com.just.agentweb.AgentWeb;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PaySuccessActivity extends BaseWebActivity {
    @BindView(R.id.ll_top_back)
    LinearLayout llTopBack;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.home_iv_readpoint)
    ImageView homeIvReadpoint;
    @BindView(R.id.iv_top_msg)
    ConstraintLayout ivTopMsg;
    @BindView(R.id.iv_top_set)
    ImageView ivTopSet;
    @BindView(R.id.iv_top_kf)
    ImageView ivTopKf;
    @BindView(R.id.page_title_layout)
    ConstraintLayout pageTitleLayout;


    @Override
    protected void initView() {
        llTopBack.setVisibility(View.VISIBLE);
        ivTopMsg.setVisibility(View.GONE);
        ivTopSet.setVisibility(View.GONE);
        ivTopKf.setVisibility(View.GONE);
        tvName.setText("号卡重开");
        String sucUrl = getIntent().getStringExtra("sucUrl");
        String signUrl = new ComPareUtils.ComPareBuilder()
                .put("token", getToken())
                .put("version", getVersion())
                .create().getSignString();

        String url =  GlobalUrls.MAIN_URL + sucUrl +
                "?token=" + getToken() + "&version=" +
                getVersion() + "&sign=" + signUrl;
        setWebViewClient(mWebViewClient);
        setWebUrl(url);
        super.initView();
    }

    private WebViewClient mWebViewClient = new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String str) {
            if (str.contains("login_out")) {
                GetUrlStr.getStrUrl(PaySuccessActivity.this);
                return true;
            }  else if (str.contains("Order/index")) {
                startActivity(new Intent(PaySuccessActivity.this, OrderListActivity.class));
                finish();
                return true;
            } else {
                return false;
            }
        }
        @SuppressLint("NewApi")
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            String str = request.getUrl().toString();
            if (str.contains("login_out")) {
                GetUrlStr.getStrUrl(PaySuccessActivity.this);
                return true;
            } else if (str.contains("Order/index")) {
                startActivity(new Intent(PaySuccessActivity.this, OrderListActivity.class));
                finish();
                return true;
            }
            return super.shouldOverrideUrlLoading(view, str);
        }
    };
}
